#include "camera.h"
#include "graphics.h"
#include <opencv2/opencv.hpp>

int main(int argc, char ** argv){
    const int ROWS = 320;
    const int COLS  = 240;

	CCamera * cam = StartCamera(ROWS,COLS,30,1,true);
    
    int numRead = 0;
    const void * temp;
    int size_temp;
    while (!numRead){
        numRead = cam->BeginReadFrame(0,temp,size_temp);
        
    }
    {
        cv::Mat im(cv::Size(ROWS,COLS), CV_8UC4);        
        im.data = (unsigned char *) temp;
        cv::imshow("im",im);
	    cv::waitKey(0);


        cam->EndReadFrame(0);
    }	
    std::cout << numRead << std::endl;
	/*
	//use fast 4-byte alignment (default anyway) if possible
	cv::glPixelStorei(GL_PACK_ALIGNMENT, (img.step & 3) ? 1 : 4);

	//set length of one complete row in destination data (doesn't need to equal img.cols)
	cv::glPixelStorei(GL_PACK_ROW_LENGTH, img.step/img.elemSize());
	
	cv::flip(im,im,0);	
    */
	
	StopCamera();
}
